package com.controller.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.apidoc.annotation.Api;
import com.apidoc.annotation.ApiAction;
import com.apidoc.annotation.ApiParam;
import com.apidoc.annotation.ApiReqParams;
import com.apidoc.annotation.ApiRespParams;
import com.apidoc.enumeration.DataType;
import com.apidoc.enumeration.Method;
import com.apidoc.enumeration.ParamType;
import com.controller.vo.ApplyVo;
import com.controller.vo.CustomerVo;
import com.dao.entity.Commissioner;
import com.service.IApplyService;
import com.service.ICommissionerService;
import com.service.ICustomerService;
import com.service.IRCustCommisService;
import com.utils.commons.ResponseBean;
import com.utils.enums.ENUM_SUCESS;

@Api(name = "普通用户操作", order = 1, mapping = "/wx")
@RestController
@RequestMapping("/wx")
public class WxCustomerController {
	
	@Autowired
	private ICustomerService customerService;
	
	@Autowired
	private ICommissionerService commissionerService;
	
	@Autowired
	private IApplyService applyService;
	
	@Autowired
	private IRCustCommisService rCustCommisService;
	
	@ApiAction(name = "获取个人信息", order = 1, mapping = "/getInfo", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "id", dataType = DataType.STRING, defaultValue = "", description = "id,参数2选一"),
			@ApiParam(name = "openId", dataType = DataType.NUMBER, defaultValue = "", description = "openid,参数2选一")
	})
	@ApiRespParams({
		@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
		@ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据"),
		@ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
	})
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/getInfo", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getInfo(CustomerVo customer) {
		try {
			return ResponseBean.of(customerService.findCustomer(customer.toPo()), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "更新个人信息", order = 2, mapping = "/updateInfo", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "account", dataType = DataType.STRING, defaultValue = "", description = "帐号"),
			@ApiParam(name = "id", dataType = DataType.STRING, defaultValue = "", required = true, description = "id"),
            @ApiParam(name = "password", dataType = DataType.STRING, defaultValue = "", description = "新的密码"),
            @ApiParam(name = "userName", dataType = DataType.STRING, defaultValue = "", description = "姓名"),
            @ApiParam(name = "idCard", dataType = DataType.STRING, defaultValue = "", description = "身份证"),
            @ApiParam(name = "sex", dataType = DataType.NUMBER, defaultValue = "", description = "0：女"),
            @ApiParam(name = "openId", dataType = DataType.NUMBER, defaultValue = "", description = "openid")
    })
    @ApiRespParams({
            @ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
            @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据"),
            @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/updateInfo", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String updateInfo(CustomerVo customer) {
		try {
			return ResponseBean.of(customerService.saveCustomer(customer.toPo()), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "专员列表查询（模糊,分页）", order = 3, mapping = "/getCommissionerList", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "userName", dataType = DataType.STRING, defaultValue = "", description = "姓名"),
			@ApiParam(name = "idCard", dataType = DataType.STRING, defaultValue = "", description = "身份证号"),
			@ApiParam(name = "page", dataType = DataType.NUMBER, defaultValue = "", description = "页数"),
			@ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小"),
			@ApiParam(name = "orderBy", dataType = DataType.STRING, defaultValue = "", description = "排序规则（字段名）"),
    })
    @ApiRespParams({
	    	@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
	        @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", object="pageUtils"),
	        @ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小", belongTo="pageUtils"),
	        @ApiParam(name = "totalPages", dataType = DataType.NUMBER, defaultValue = "", description = "总页数", belongTo="pageUtils"),
	        @ApiParam(name = "totalElements", dataType = DataType.NUMBER, defaultValue = "", description = "总数", belongTo="pageUtils"),
	        @ApiParam(name = "content", dataType = DataType.OBJECT, defaultValue = "", description = "列表数据", belongTo="pageUtils", object="TempStaff"),
	        
	        @ApiParam(name = "id", dataType = DataType.NUMBER, defaultValue = "", description = "id", belongTo="TempStaff"),
	        @ApiParam(name = "userName", dataType = DataType.NUMBER, defaultValue = "", description = "姓名", belongTo="TempStaff"),
	        @ApiParam(name = "idCard", dataType = DataType.NUMBER, defaultValue = "", description = "身份证", belongTo="TempStaff"),
	        @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/getCommissionerList", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getCommissionerList(Commissioner c, Integer page, Integer size, String orderBy) {
		try {
			return ResponseBean.of(commissionerService.findUserByCondition(c, page, size, orderBy), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "模拟贷款，返回银行列表", order = 4, mapping = "/testApply", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "customerId", dataType = DataType.STRING, defaultValue = "", required = true, description = "客户id"),
			@ApiParam(name = "age", dataType = DataType.STRING, defaultValue = "", required = true, description = "客户当前年龄"),
            @ApiParam(name = "loanAge", dataType = DataType.STRING, defaultValue = "", required = true, description = "贷款年限"),
            @ApiParam(name = "houseAge", dataType = DataType.STRING, defaultValue = "", required = true, description = "房龄"),
            @ApiParam(name = "landType", dataType = DataType.STRING, defaultValue = "", required = true, description = "出让地，划拨地"),
            @ApiParam(name = "isEconomize", dataType = DataType.NUMBER, defaultValue = "", required = true, description = "是否经济适用房,1:是,0:不是")
    })
    @ApiRespParams({
            @ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
            @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", object = "obj"),
            @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", belongTo = "obj"),
            @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/testApply", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String testApply(ApplyVo vo) {
		try {
			return ResponseBean.of(applyService.applySupport(vo.toPo(), 1, 150), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "贷款", order = 5, mapping = "/doApply", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "customerId", dataType = DataType.STRING, defaultValue = "", description = "客户id"),
			
			@ApiParam(name = "sex", dataType = DataType.STRING, defaultValue = "", description = "客户性别"),
			@ApiParam(name = "userName", dataType = DataType.STRING, defaultValue = "", description = "客户姓名"),
			@ApiParam(name = "idCard", dataType = DataType.STRING, defaultValue = "", description = "客户身份证"),
			@ApiParam(name = "phone", dataType = DataType.STRING, defaultValue = "", description = "客户电话（账号）"),
			
			@ApiParam(name = "commisId", dataType = DataType.STRING, defaultValue = "", required = true, description = "专员id"),
			@ApiParam(name = "age", dataType = DataType.STRING, defaultValue = "", required = true, description = "客户当前年龄"),
			@ApiParam(name = "loanAge", dataType = DataType.STRING, defaultValue = "", required = true, description = "贷款年限"),
			@ApiParam(name = "houseAge", dataType = DataType.STRING, defaultValue = "", required = true, description = "房龄"),
			@ApiParam(name = "landType", dataType = DataType.STRING, defaultValue = "", required = true, description = "出让地，划拨地"),
			@ApiParam(name = "bankId", dataType = DataType.STRING, defaultValue = "", description = "银行id"),
			@ApiParam(name = "bankName", dataType = DataType.STRING, defaultValue = "", description = "银行名"),
			@ApiParam(name = "isEconomize", dataType = DataType.NUMBER, defaultValue = "", required = true, description = "是否经济适用房,1:是,0:不是")
	})
	@ApiRespParams({
		@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
		@ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", object = "obj"),
		@ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", belongTo = "obj"),
		@ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
	})
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/doApply", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String doApply(ApplyVo vo) {
		try {
			return ResponseBean.of(applyService.doApply(vo.toPo(), 1, 150), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
	
	@ApiAction(name = "我的专员列表", order = 3, mapping = "/getMyCommis", method = Method.POST)
	@ApiReqParams(type = ParamType.URL_PARAM, value = {
			@ApiParam(name = "customerId", dataType = DataType.NUMBER, defaultValue = "", required = true, description = "客户id"),
			@ApiParam(name = "page", dataType = DataType.NUMBER, defaultValue = "", description = "页数"),
			@ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小"),
    })
    @ApiRespParams({
	    	@ApiParam(name = "status", dataType = DataType.NUMBER, defaultValue = "", description = "状态码"),
	        @ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "", description = "响应数据", object="pageUtils"),
	        @ApiParam(name = "size", dataType = DataType.NUMBER, defaultValue = "", description = "页大小", belongTo="pageUtils"),
	        @ApiParam(name = "totalPages", dataType = DataType.NUMBER, defaultValue = "", description = "总页数", belongTo="pageUtils"),
	        @ApiParam(name = "totalElements", dataType = DataType.NUMBER, defaultValue = "", description = "总数", belongTo="pageUtils"),
	        @ApiParam(name = "content", dataType = DataType.OBJECT, defaultValue = "", description = "列表数据", belongTo="pageUtils", object="TempStaff"),
	        
	        @ApiParam(name = "id", dataType = DataType.NUMBER, defaultValue = "", description = "id", belongTo="TempStaff"),
	        @ApiParam(name = "userName", dataType = DataType.NUMBER, defaultValue = "", description = "姓名", belongTo="TempStaff"),
	        @ApiParam(name = "idCard", dataType = DataType.NUMBER, defaultValue = "", description = "身份证", belongTo="TempStaff"),
	        @ApiParam(name = "sex", dataType = DataType.NUMBER, defaultValue = "", description = "性别，女0,男1", belongTo="TempStaff"),
	        @ApiParam(name = "text", dataType = DataType.STRING, defaultValue = "", description = "提示信息")
    })
	@CrossOrigin(origins = "*")
	@RequestMapping(value = "/getMyCommis", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getMyCommis(Long customerId, Integer page, Integer size) {
		try {
			return ResponseBean.of(rCustCommisService.getMyCommis(customerId, page, size), ENUM_SUCESS.SUCESS.value);
		} catch (Exception e) {
			return ResponseBean.of(ENUM_SUCESS.FAILED.value, e.getMessage());
		}
	}
}
